﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project2
{
    //父类
    public class parentA
    {
        public virtual void Mymethod()
        {
            Console.WriteLine("This method in parentA");
        }
    }

    public class childA : parentA
    {
        public new void Mymethod()
        {
            Console.WriteLine("This method in childA");
        }
    }

    public class parentB
    {
        public virtual void Mymethod()
        {
            Console.WriteLine("This method in parentB");
        }
    }

    public class childB : parentB
    {
        public override void Mymethod()
        {
            Console.WriteLine("This method in childB");
        }
    }

    public class parentC
    {
        public virtual void Mymethod()
        {
            Console.WriteLine("This method in parentC");
        }
    }

    public class childC : parentC
    {
        public new void Mymethod()
        {
            base.Mymethod();
            Console.WriteLine("This method in childC");
        }
    }

    //https://www.cnblogs.com/tiancai/p/4591731.html

    internal class newAndOverride
    {
        private static void MainnewAndOverride(string[] args)
        {
            parentA parentA = new childA();//new把父类的方法隐藏了，父类看不到子类的方法了
            parentA.Mymethod();
            childA childA = new childA();
            childA.Mymethod();

            parentB parentB = new childB();
            parentB.Mymethod();
            childB childB = new childB();
            childB.Mymethod();

            parentC parentC = new childC();
            parentC.Mymethod();
            childC childC = new childC();
            childC.Mymethod();
        }
    }
}